﻿<%@ Page Title="" Language="C#" MasterPageFile="~/PIMMobile.master" AutoEventWireup="true" CodeFile="NewRecipe.aspx.cs" Inherits="NewRecipe" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="stylesheet" href="jquery/jRating.jquery.css" type="text/css" />
    <script type="text/javascript" src="jquery/jRating.jquery.js"></script>
<script type="text/javascript">
   
    function getFile() {
        document.getElementById("fImageUpload").click();
        return false;
    }
    function readURL(input) {
        //alert(input);
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                document.getElementById("Image2").src = e.target.result;
                var object = e.target.result;
                object = object.replace('data:image/png;base64,', '');
                object = object.replace('data:image/png;base64,', '');
                object = object.replace('data:image/jpg;base64,', '');
                object = object.replace('data:image/gif;base64,', '');
                object = object.replace('data:image/jpeg;base64,', '');
                object = object.replace('data:image/bmp;base64,', '');
                object = object.replace('data:image/Icon;base64,', '');
                document.getElementById("<%=hdImage.ClientID%>").value = object;
                alert(object);
            };
            reader.readAsDataURL(input.files[0]);
            return false;
        }
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="width:100%;height:130px; float:left; margin:5px;">
    <div style="float:left; width:30%;">
        <div style=" border:1px #ffffff; height:90px; text-align:center;" >
            <img id="Image2" class="img_border">
        </div>
        <div style="text-align:center; " >
            <div class="basic" style="margin:0 auto;"  data-average="0" data-id="1"></div>
            <asp:Button ID="btnUpload" Width="90" runat="server" Text="Upload"  OnClientClick="return getFile()" />
            <asp:HiddenField id="hdImage" runat="server"/>
        </div>
    </div>
    <div style="width:60%;float:left; margin:0 auto;" >
        <asp:TextBox runat="server" ID="txtRecipeName" placeholder="Recipe Name" MaxLength="50" CssClass="textInputs "></asp:TextBox>
        <div style=" margin-top:5px;width:30%">
        <asp:TextBox runat="server" ID="txtServing" placeholder="Serving" MaxLength="10" CssClass="textInputs "></asp:TextBox>
        </div>
        <div style="margin-top:5px; ">
            <input type="checkbox" id="chIsPublish" checked="true" runat="server" name="vehicle"
                value="1" />Share with others
        </div>
    </div>
    <div style="overflow: hidden; height: 0px; width: 0px;">
                        <input type="file"   id="fImageUpload" onchange="readURL(this);"/>
    </div> 
</div>
<div style="clear:both"></div>
<div style="width:100%; margin:5px ">
    <div style="width:97%;"> 
        <asp:TextBox runat="server" ID="txtDescription" placeholder="Description"   CssClass="textInputs "></asp:TextBox>
    </div>
    <div style="width:97%; margin-top:10px;"> 
        <asp:TextBox runat="server" ID="txtIngredient" TextMode="MultiLine" placeholder="Ingredients"  CssClass="textAreaBoxInputs "></asp:TextBox>
    </div>
    <div style="width:97%; margin-top:10px ;" > 
        <asp:TextBox runat="server" ID="txtRecDirection" TextMode="MultiLine" placeholder="Direction" CssClass="textAreaBoxInputs "></asp:TextBox>
    </div>
</div>
<div>
    <div style="width:100%; text-align:center;">
       <asp:Button runat="server" id="btnSave" Text="Save" CssClass="save_button" 
            onclick="btnSave_Click" /> 
    </div>
</div>
<script type="text/javascript">

    function initRating() {
        var userid = '<%=Session["Userid"]%>';
        //        if (document.getElementById("ratingStar").value != "") {
        //            //alert(userid);
        //            $(".basic").attr('data-average', document.getElementById("ratingStar").value);
        //        } else {
        //            $(".basic").attr('data-average', '0');
        //        }
        if (userid != "") {
            //alert(recipeID);
            $(".basic").jRating({
                step: true,
                length: 5,
                decimalLength: 1,
                smallStarsPath: 'jquery/icons/small.png',
                onSuccess: function (element, rate) {
                    document.getElementById("ratingStar").value = rate;
//                    if (recipeID != null)
//                        submitRating(rate);
                },
                onError: function () {
                    alert('Error : please retry');
                }
            });

        } else {
            $(".basic").jRating({
                isDisabled: true
            });
        }
        //return false;
    }
    

    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
    </script>
    <asp:HiddenField id="ratingStar" runat="server"/>
</asp:Content>

